package com.ruoyi.system.util;

import java.util.Date;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.LocalTime;

public class DateUtils {
    //  获取某天的开始时间
    public static Date getStartOfDay(Date date) {
        LocalDateTime localDateTime = date.toInstant()
                .atZone(ZoneId.systemDefault())
                .toLocalDateTime()
                .with(LocalTime.MIN);

        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }

    //  获取某天的结束时间
    public static Date getEndOfDay(Date date) {
        LocalDateTime localDateTime = date.toInstant()
                .atZone(ZoneId.systemDefault())
                .toLocalDateTime()
                .with(LocalTime.MAX);

        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }
}
